<template>
  <van-cell class="comment-item">
    <van-image
      slot="icon"
      class="avatar"
      round
      fit="cover"
      :src="CommitItemObj.aut_photo"
    />
    <div slot="title" class="title-wrap">
      <div class="user-name">{{ CommitItemObj.aut_name }}</div>
      <van-button
        class="like-btn"
        @click="MyPraise"
        :class="CommitItemObj.is_liking ? 'icon_myPraise' : ''"
        :icon="CommitItemObj.is_liking ? 'good-job' : 'good-job-o'"
        >{{ CommitItemObj.like_count || '赞' }}</van-button
      >
    </div>
    <div slot="label">
      <p class="comment-content">{{ CommitItemObj.content }}</p>
      <div class="bottom-info">
        <span class="comment-pubdate">{{ timeFrom }}</span>
        <van-button
          class="reply-btn"
          round
          @click="$emit('Reply', CommitItemObj, index)"
          >回复 {{ CommitItemObj.reply_count }}
        </van-button>
      </div>
    </div>
  </van-cell>
</template>

<script>
import dayjs from '@/utils/dayjs'
import { CommentLikingsAPI, noCommentLikingsAPI } from '@/api'
export default {
  props: {
    CommitItemObj: {
      type: Object,
      required: true
    },
    index: {
      type: Number
    }
  },
  computed: {
    timeFrom() {
      return dayjs(this.CommitItemObj.pubdate).fromNow()
    }
  },
  methods: {
    // 点赞评论
    async MyPraise() {
      // (this.CommitItemObj.com_id)
      if (!this.CommitItemObj.is_liking) {
        const { data } = await CommentLikingsAPI(this.CommitItemObj.com_id)
        // this.CommitItemObj.is_liking = true
        this.$emit('update-is_liking', this.index, true)
        this.$toast.success('点赞成功')
      } else {
        const { data } = await noCommentLikingsAPI(this.CommitItemObj.com_id)
        this.$emit('update-is_liking', this.index, false)
        this.$toast.success('取消点赞成功')
      }
    }
  }
}
</script>
<style scoped lang="less">
.comment-item {
  .avatar {
    width: 72px;
    height: 72px;
    margin-right: 25px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .user-name {
      color: #406599;
      font-size: 26px;
    }
  }
  .comment-content {
    font-size: 32px;
    color: #222222;
    word-break: break-all;
    text-align: justify;
  }
  .comment-pubdate {
    font-size: 19px;
    color: #222;
    margin-right: 25px;
  }
  .bottom-info {
    display: flex;
    align-items: center;
  }
  .reply-btn {
    width: 135px;
    height: 48px;
    line-height: 48px;
    font-size: 21px;
    color: #222;
  }
  .like-btn {
    height: 30px;
    padding: 0;
    border: none;
    font-size: 19px;
    line-height: 30px;
    margin-right: 7px;
    .van-icon {
      font-size: 30px;
    }
  }
  .icon_myPraise {
    color: #ee725b;
  }
}
</style>
